// 模拟本地数据库
const db = {
  // 本地存储键名
  STORAGE_KEY: {
    LIVE_LIST: 'mock_live_data',
    USER_INFO: 'mock_user_data'
  },

  // 初始化数据
  initData() {
    const defaultLiveList = [
      {
        id: 1,
        cover: '/images/live1.jpg',
        title: '时尚杂志直播',
        tag: '穿搭教学',
        timer: 300, // 单位：秒
        likeCount: 156,
        isLiked: false
      }
    ];
    
    wx.setStorageSync(this.STORAGE_KEY.LIVE_LIST, defaultLiveList);
    wx.setStorageSync(this.STORAGE_KEY.USER_INFO, { nickname: '用户' });
  },

  // 获取直播列表
  getLiveList() {
    return wx.getStorageSync(this.STORAGE_KEY.LIVE_LIST) || [];
  },

  // 更新点赞状态
  updateLike(id) {
    const list = this.getLiveList();
    const newList = list.map(item => {
      if (item.id === id) {
        return {
          ...item,
          isLiked: !item.isLiked,
          likeCount: item.likeCount + (item.isLiked ? -1 : 1)
        };
      }
      return item;
    });
    wx.setStorageSync(this.STORAGE_KEY.LIVE_LIST, newList);
    return newList;
  }
};

export default db;
